﻿using System;
using System.Data.Common;
using MySql.Data.MySqlClient;
using PTop.Data;
using PTop.Domain.Entity.Article;
using PTop.Domain.IRepository.Article;

namespace PTop.Repository.Article
{
    /// <summary>
    /// ArticleRepository
    /// </summary>	
    public class ArticleRepository : RepositoryBase<ArticleEntity>, IArticleRepository
    {
        public void UpdateNumber(string type, string articleId)
        {
            var sql = "";
            switch (type)
            {
                case "CommentNumber":
                    sql = "UPDATE Train_Article SET F_CommentNumber = F_CommentNumber + 1 WHERE F_Id = @articleId";
                    break;
                case "ClickNumber":
                    sql = "UPDATE Train_Article SET F_ClickNumber = F_ClickNumber + 1 WHERE F_Id = @articleId";
                    break;
                default:
                    throw new Exception("type is not available");
            }
            DbParameter[] parameter = 
            {
                 new MySqlParameter("@articleId",articleId)
            };
            ExcecuteNonQuery(sql, parameter);
        }
    }
}